from moviepy.editor import VideoFileClip
import ffmpeg


# 视频格式转换
def video_format_conversion(input_video_file, output_video_file):
    try:
        ffmpeg.input(input_video_file).output(output_video_file).run()
    except:
        pass
    print(f"转换完成;{output_video_file}")


# 视频长度剪切
def video_duration_cut(input_video_file, start_cut, end_cut):
    clip = VideoFileClip(input_video_file)
    clip = clip.subclip(start_cut, end_cut)
    input_video_file_list = input_video_file.split(".")
    # 组装输出视频名称格式
    output_video_file = input_video_file_list[0] + "_" + str(start_cut) + "-" + str(end_cut) + "." + \
                        input_video_file_list[1]
    clip.write_videofile(output_video_file)
    print(f"已经完成{output_video_file}")


input_video_file = r"/Users/admin/Desktop/视频资源/202404301.mp4"
conversion_list = ["AVI", "mpeg", "wmv", "mov", "mpeg2", "rmvb", "asf", '3gp', 'flv', 'swf']
for conversion in conversion_list:
    output_video_file = input_video_file.split('.')[0] + "ffmeg" + "." + conversion
    try:
        video_format_conversion(input_video_file, output_video_file)
    except:
        pass
